package com.itheima.test04;

import java.io.*;
import java.net.Socket;

/*
发送端
读取本地文件

将本地文件上传至 服务器

从服务器获取结果
打印结果

释放资源


 */
public class ClientDemo {


    public static void main(String[] args) throws IOException {
        //读取本地文件
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("C:\\Users\\Administrator\\Desktop\\美女.png"));
        //将本地文件上传至 服务器
        //获取输出流
        Socket socket = new Socket("127.0.0.1", 8888);
        OutputStream os = socket.getOutputStream();
        byte[] bytes= new byte[1024];
        int len;
        while ((len=bis.read(bytes))!=-1){
            os.write(bytes,0,len);
        }
       //来个结束标记
       socket.shutdownOutput();
        //从服务器获取结果
        InputStream is = socket.getInputStream();
        //字节 -> 字符
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        String s;
        while ((s=reader.readLine())!=null){
            //打印结果
            System.out.println(s);
        }

        //释放资源
        bis.close();
        socket.close();

    }
}
